//
//  VVSportGPSButton.m
//  DingDingSport
//
//  Created by 王惠平 on 2017/4/26.
//  Copyright © 2017年 will wang. All rights reserved.
//

#import "VVSportGPSButton.h"
#import "VVSportTrack.h"

@implementation VVSportGPSButton

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    //监听GPS通知
    
    //监听通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeGPSStateNote:) name:@"VVSportGPSStateDidChangeNote" object:nil];
}

//更新Gps信息后调用
- (void) didChangeGPSStateNote:(NSNotification *)note {
    
    VVSportGPSState state = [note.userInfo[@"VVSportGPSStateDidChangeNoteGPSStateKey"]unsignedIntegerValue];
    
    NSString *content;
    NSString *imgName;
    
    switch (state) {
        case VVSportGPSStateDisconnect:{
            
            //设置图片
            imgName = _isTrackBtn ? @"ic_sport_gps_map_disconnect" : @"ic_sport_gps_disconnect";
            
            //设置文字
            content = @" GPS断开 ";
        }
            break;
            
        case VVSportGPSStateBad:{
            
            //设置图片
            imgName = _isTrackBtn ? @"ic_sport_gps_map_connect_1" : @"ic_sport_gps_connect_1";
            
            //设置文字
            content = @" 请绕开大楼 ";
        }
            break;
            
        case VVSportGPSStateNormal:{
            
            //设置图片
            imgName = _isTrackBtn ? @"ic_sport_gps_map_connect_2" : @"ic_sport_gps_connect_2";
            
            //设置文字
            content = nil;
        }
            break;
            
        case VVSportGPSStateGood:{
            
            //设置图片
            imgName = _isTrackBtn ? @"ic_sport_gps_map_connect_3" : @"ic_sport_gps_connect_3";
            
            //设置文字
            content = nil;
        }
            break;
            
        default:
            break;
    }
    
    [self setTitle:content forState:UIControlStateNormal];
    
    [self setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    
}


@end
